

<neos type="view" name="head"/>

<script type="text/javascript"> function aparece(x){if(x.style.display == 'block'){x.style.display = 'none';} else{x.style.display = 'block';};}function desaparece(x){x.style.display = 'none';}</script>

<?php
if($_SESSION['tipoUsuario'] == 1 || $_SESSION['tipoUsuario'] == 2)
    echo "<body  onload=\"aparece( bt2);aparece( bt4);aparece( bt5);\">";
else
	echo "<body  onload=\"aparece( bt2);aparece( bt1);aparece( bt4);aparece( bt5);\">";
?>

<div class="pagina1">


		<div class="links"><a href="<neos:url/>sair">Logoff</a> | <a href="<neos:url/>CLogin/Redirect">Menu</a></div>

		<!-- Botoes de opcao -->
		<div id="bt">

			<input  class="botao" id = "bt1"  type="submit" name="bt1" value="      Cadastrar         " style="display:none" onclick= "aparece(cadastrar_minicurso);desaparece(frm_cursos);desaparece(frm_editcursos);desaparece(frm_editcursos1);desaparece(frm_meuscursos);desaparece(cancelar)"/>

			<input  class="botao" id = "bt2" type="submit" name="bt2" value="       Matricular        " style="display:none" onclick= "aparece(frm_cursos);desaparece(cadastrar_minicurso);desaparece(frm_editcursos);desaparece(frm_editcursos1);desaparece(frm_meuscursos);desaparece(cancelar)"/>

			<!--<input id = "bt3" type="submit" name="bt3" value="Editar" onclick= "aparece(frm_editcursos);desaparece(frm_cursos);desaparece(cadastrar_minicurso);desaparece(frm_editcursos1);desaparece(frm_meuscursos);desaparece(cancelar)"/> -->
 
			<input  class="botao" id = "bt4" type="submit" name="bt4" value=" Meus Minicursos   " style="display:none" onclick= "aparece(frm_meuscursos);desaparece(frm_cursos);desaparece(frm_editcursos);desaparece(cadastrar_minicurso);desaparece(frm_editcursos1);desaparece(cancelar);"/>
 
			<input  class="botao" id = "bt5" type="submit" name="bt5" value="   Desmatricular    " style="display:none" onclick= "aparece(cancelar);desaparece(frm_cursos);desaparece(frm_editcursos);desaparece(cadastrar_minicurso);desaparece(frm_editcursos1);desaparece(frm_meuscursos);"/>
 
		</div>
		
		<!-- Cadastrar novo minicurso-->
		<div id = "cadastrar_minicurso" class="formulario" style="display:none" >
			<br /><br /><br /><br />
			<form action="<neos:url/>editminicurso/cadastrar" name="frm_cadastro" method="post">
				<h2>Dados do Minicurso</h2>
				<label>Nome:</label>
				<input name="nome" type="text" id="nome" size="100" maxlength="100" />
				<label>Descricao:</label>
				<input name="descricao" type="text" id = "descricao" size="100" maxlength="100" />
				<label>Carga Horaria:</label>
				<input name="carga_horaria" type="text" id="carga_horaria" size="3" maxlength="3" onkeypress="maskIt(this,event,'##h"/><!--12h-->
				<label>Horarios 1:</label>
				<input name="horarios1" type="text" id="horarios1" size="13" maxlength="13"  onkeypress="maskIt(this,event,'##:## - ##:##')"/>  <!--Ex.: 12:00 - 13:00-->
				<label>Horarios 2:</label>
				<input name="horarios2" type="text" id="horarios2" size="13" maxlength="13" onkeypress="maskIt(this,event,'##:## - ##:##')"/><!--Ex.: 12:00 - 13:00-->
				<label>Datas 1:</label>
				<input name="datas1" type="text" id="datas1" size="20" maxlength="20" onkeypress="maskIt(this,event,'##/##/#### - ##/##/####')"/><!--12/12/2011-->
				<label>Datas 2:</label>
				<input name="datas2" type="text" id="datas2" size="20" maxlength="20" onkeypress="maskIt(this,event,'##/##/#### - ##/##/####')"/><!--12/12/2011-->
				<label>Pre requisitos:</label>
				<input name="pre_requisitos" type="text" id="pre_requisitos" size="100" maxlength="100" />
				<label>Professor:</label>
				<input name="professor" type="text" id="professor" size="100" maxlength="100" />
				<label>Numero de vagas:</label>
				<input name="n_vagas" type="text" id="n_vagas" size="3" maxlength="3" />

				<input type="submit" value="Cadastrar" />
			</form>
		</div>
		
		<!-- Matricular em minicurso-->
		<br /><br /><br /><br />
		<center>
			<form action="<neos:url/>editminicurso/matricular" id = "frm_cursos" style="display:none" name="frm_cursos"  method = "post">

				<?php
					$sql = _db("SELECT * FROM minicursos");
					
					
					echo "<TABLE BORDER=1>
						<TH></TH><TH>Nome</TH><TH> Horario 1 </TH><TH> Horario 2 </TH><TH> Vagas </TH>";
					foreach($sql as $i){
						$aux = $i->horarios;
						$h = explode(";", $aux );
						$aux = $i->datas;
						$d = explode(";", $aux );
						$d[0] = explode("-", $d[0]);
						$d[0] = $d[0][2]."/".$d[0][1]."/".$d[0][0];
						$d[1] = explode("-", $d[1]);
						$d[1] = $d[1][2]."/".$d[1][1]."/".$d[1][0];
						
						//calcula as vagas restantes
						$sqlp = _db("SELECT * FROM `participacoesminicursos` WHERE minicurso_id = '". $i->id ."'");
						$sqlm = _db("SELECT n_vagas FROM `minicursos` WHERE id = '". $i->id ."'");
						$vagas_restantes =   (int)$sqlm[0]->n_vagas - (int)count($sqlp);
						
						echo "<TR><TD><center><input type=\"checkbox\" name=\"curso=" . $i->id .  "\" id=\"valor\" value=\"1\" /> </center></TD>
						<TD><center>". $i->nome."</center></TD><TD><center>".$d[0]."<br /> ".$h[0]."</center></TD><TD><center>".$d[1]."<br /> ".$h[1]."</center></TD><TD><center>".$vagas_restantes."</center></TD></TR>";
					}
					echo "</TABLE>";
				?>
				<br /><br />
				<input type="submit" value="Matricular" />
				
			</form>
		</center>
		
		<!--nao esta funcionando editar minicurso-->
		<center>
			<div id="frm_editcursos"  style="display:none" name="frm_editcursos">
				<?php
					$sql = _db("SELECT * FROM minicursos");
					echo "<TABLE BORDER=1>
						<TH></TH><TH>Nome</TH><TH> Horario 1 </TH><TH> Horario 2 </TH>";
					foreach($sql as $i){
						$aux = $i->horarios;
						$h = explode(";", $aux );
						$aux = $i->datas;
						$d = explode(";", $aux );
						echo "<TR><TD><center><input type=\"checkbox\" name=\"curso=" . $i->id .  "\" id=\"curso=" . $i->id .  "\" value=1 onClick = \"eid.value='".$i->id."';enome.value='".$i->nome."';edescricao.value='".$i->descricao."';ecarga_horaria.value='".$i->carga_horaria."';ehorarios1.value='".$h[0]."';ehorarios2.value='".$h[1]."'; edatas1.value='".$d[0]."'; edatas2.value='".$d[1]."';epre_requisitos.value='".$i->pre_requisitos."';eprofessor.value='".$i->professor."';en_vagas.value='".$i->n_vagas."'; \"/> </center></TD>
						<TD><center>". $i->nome."</center></TD><TD><center>".$d[0]."<br /> ".$h[0]."</center></TD><TD><center>".$d[1]."<br /> ".$h[1]."</center></TD></TR>";
					}
					echo "</TABLE>";
				?>
				<br /><br />
				<button type="button"  onclick= "aparece(frm_editcursos1);aparece(frm_editcursos);">Editar</button>
			</div>
		</center>
		
		<div id = "frm_editcursos1" class="formulario" style="display:none" >
			<br /><br /><br /><br />
			<form action="<neos:url/>editminicurso/editacadastrar" name="frm_cadastro1" method="post">
					<h2>Dados do Minicurso</h2>
					<input name="eid" type="text" id="eid" size="100" maxlength="100" style="display:none" />
					<label>Nome:</label>
					<input name="enome" type="text" id="enome" size="100" maxlength="100" />
					<label>Descricao:</label>
					<input name="edescricao" type="text" id = "edescricao" size="100" maxlength="100" />
					<label>Carga Horaria:</label>
					<input name="ecarga_horaria" type="text" id="ecarga_horaria" size="4" maxlength="100" /><!--12h-->
					<label>Horarios 1:</label>
					<input name="ehorarios1" type="text" id="ehorarios1" size="15" maxlength="100"  />  <!--Ex.: 12:00 - 13:00-->
					<label>Horarios 2:</label>
					<input name="ehorarios2" type="text" id="ehorarios2" size="15" maxlength="100" /><!--Ex.: 12:00 - 13:00-->
					<label>Datas 1:</label>
					<input name="edatas1" type="text" id="edatas1" size="11" maxlength="100" /><!--12/12/2011-->
					<label>Datas 2:</label>
					<input name="edatas2" type="text" id="edatas2" size="11" maxlength="100" /><!--12/12/2011-->
					<label>Pre requisitos:</label>
					<input name="epre_requisitos" type="etext" id="epre_requisitos" size="100" maxlength="100" />
					<label>Professor:</label>
					<input name="eprofessor" type="text" id="eprofessor" size="100" maxlength="100" />
					<label>Numero de vagas:</label>
					<input name="en_vagas" type="text" id="en_vagas" size="3" maxlength="100" />
					
					<input type="submit" value="editar" />
				</form>
		</div>
		
		<!--meus minicurso-->
		<center>
			<div id="frm_meuscursos"  style="display:none" name="frm_meuscursos">
				<?php
					$id_usuario = $_SESSION['idUsuario'];
					$sql = _db("SELECT  m.nome, pa.status_id FROM participacoesminicursos pa JOIN usuarios u ON ( u.id = pa.usuario_id ) JOIN pessoas pe ON ( pe.id = pessoa_id ) join minicursos m on (m.id = pa.minicurso_id) WHERE pa.usuario_id = '".$id_usuario."'");
										
					echo "<TABLE BORDER=1>
						<TH>Nome</TH><TH> Status </TH>";
					foreach($sql as $i){
						$status = _db("SELECT descricao FROM status WHERE id = '".$i->status_id."'");
						echo "<TR><TD><center>". $i->nome."</center></TD><TD><center>". $status[0]->descricao."</center></TD></TR>";
					}
					echo "</TABLE>";
				?>
			</div>
		</center>
		
		<center>
			<form action="<neos:url/>editminicurso/desmatricular" id = "cancelar" style="display:none" name="cancelar"  method = "post">
				<?php
					$sql = _db("SELECT pa.usuario_id, pa.minicurso_id, m.nome, pa.status_id FROM participacoesminicursos pa JOIN usuarios u ON ( u.id = pa.usuario_id ) JOIN pessoas pe ON ( pe.id = pessoa_id ) join minicursos m on (m.id = pa.minicurso_id) WHERE pa.usuario_id = '".$id_usuario."' and  pa.status_id = 3");
					
					
					echo "<TABLE BORDER=1>
						<TH></TH><TH>Nome</TH>";
					foreach($sql as $i){						
						echo "<TR><TD><center><input type=\"checkbox\" name=\"curso=" . $i->minicurso_id .  "\" id=\"valor\" value=\"1\" /> </center></TD>
						<TD><center>". $i->nome."</center></TD></TR>";
					}
					echo "</TABLE>";
				?>
				<br /><br />
				<input type="submit" value="Desmatricular" />
			</form>
		</center>
		
    <!--
	<div class="texto_cadastro">
		<h3>Instru&ccedil;&otilde;es:</h3>
		<p>Preencha tudo...</p>
	</div>
    -->
</div>
<neos type="view" name="footer"/>
